﻿package view.task
{
    import cmd.*;
    import com.core.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import manager.*;
    import morn.core.components.*;
    import view.message.*;

    public class EMSItem extends Component
    {
        private var _txt1:Label;
        private var _count:int = 0;
        private var toX:int = 248;
        private var toY:int = 377;
        private var toStageid:int = 1027;

        public function EMSItem()
        {
            var _loc_2:Boolean = true;
            mouseEnabled = true;
            mouseChildren = _loc_2;
            this._txt1 = new Label(MColor.getHMTL("[经验]", 6) + "<u>押运镖车</u>");
            this._txt1.isHtml = true;
            this._txt1.color = MColor.New16;
            this._txt1.align = "left";
            this._txt1.stroke = "0x0";
            this._txt1.addEventListener(MouseEvent.CLICK, this.linkHandler);
            this.addChild(this._txt1);
            var _loc_1:* = UserData.getOnlineData();
            if (_loc_1)
            {
                this.updateCount(_loc_1);
            }
            return;
        }// end function

        private function linkHandler(event:MouseEvent) : void
        {
            var roledata:Object;
            var cost:int;
            var e:* = event;
            if (this._count > 0)
            {
                Alert2.show("即将传送，是否确认前往！", "温馨提示", ["确定", "取消"], function (param1:int, param2:Object) : void
            {
                var _loc_3:Object = null;
                var _loc_4:Object = null;
                var _loc_5:int = 0;
                if (param1 == 0)
                {
                    _loc_3 = ConfigDictionary.data.sysnpc;
                    for each (_loc_4 in _loc_3)
                    {
                        
                        if (_loc_4.npcid == 1099)
                        {
                            _loc_5 = 1099;
                            ModelProxy.change("data", "taskfindpath", _loc_5);
                            ModelProxy.change("zone", "stopGuaji", null);
                            PluginManager.instance.sendToServer("activity", CMDActivity.Trans, {x:_loc_4.x, y:_loc_4.y, tostageid:_loc_4.stageid, free:1});
                            ModelProxy.change("zone", "autoMove", {x:_loc_4.x, y:_loc_4.y, tostageid:_loc_4.stageid, onhorse:true});
                        }
                    }
                }
                return;
            }// end function
            );
            }
            else
            {
                roledata = UserData.getOnlineData();
                if (roledata && roledata.emsbuy < 3)
                {
                    cost = roledata.emsbuy * 500 + 500;
                    Alert2.show("今日押运次数已用完，等待明天刷新，或花费" + cost + "元宝购买押运次数，确定要购买吗？", "", ["确定", "取消"], function (param1:int, param2:Object) : void
            {
                if (param1 == 0)
                {
                    PluginManager.instance.sendToServer("ems", CMDEms.EMSBuy, null);
                }
                return;
            }// end function
            );
                }
                else
                {
                    ModelProxy.change("movetips", "error", "购买次数已经用完");
                }
            }
            return;
        }// end function

        public function updateCount(param1:Object) : void
        {
            var _loc_2:int = 0;
            if (this._txt1)
            {
                _loc_2 = 2 - int(param1.ems);
                this._count = _loc_2;
                if (_loc_2 > 0)
                {
                    this._txt1.text = MColor.getHMTL("[经验]", 6) + "<u>押运镖车</u>";
                }
                else
                {
                    this._txt1.text = MColor.getHMTL("[经验]", 6) + MColor.getHMTL("<u>押运镖车</u>", 9);
                }
            }
            return;
        }// end function

    }
}
